<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>易卖管理系统</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/bootstrap.min.css'">
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/font-awesome.min.css'">
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/AdminLTE.min.css'">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/all-skins.min.css'">
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/main.css'">
    <link rel="stylesheet" th:href="${#request.contextPath} + '/static/css/public.css'" media="all" />
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>

    <![endif]-->

</head>
<!---->
<body class="loginBody">
<div class="login-box" id="app" v-cloak>
    <div class="login-logo">
        <b style="color: white">易卖管理系统</b>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
        <p class="login-box-msg">管理员登录</p>
        <div v-if="error" class="alert alert-danger alert-dismissible">
            <h4 style="margin-bottom: 0px;"><i class="fa fa-exclamation-triangle"></i> {{errorMsg}}</h4>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="loginname" placeholder="账号">
            <span class="glyphicon glyphicon-user form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="password" class="form-control" v-model="pwd" placeholder="密码">
            <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <input type="text" class="form-control" v-model="captcha" @keyup.enter="login" placeholder="验证码">
            <span class="glyphicon glyphicon-warning-sign form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
            <img alt="如果看不清楚，请单击图片刷新！" class="pointer" :src="src" @click="refreshCode">
            &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" @click="refreshCode">点击刷新</a>
        </div>

        <div class="row">
            <div class="col-xs-8">
                <div class="checkbox icheck">
                </div>
            </div>
            <!-- /.col -->
            <div class="col-xs-4">
                <button type="button" class="btn btn-primary btn-block btn-flat" @click="login">登录</button>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.social-auth-links -->

    </div>
    <!-- /.login-box-body -->
</div>
<!-- /.login-box th:href="${#request.getContextPath()}+-->
<script th:src="${#request.getContextPath()}+'/static/libs/jquery.min.js'"></script>
<script th:src="${#request.getContextPath()}+'/static/libs/vue.min.js'"></script>
<script th:src="${#request.getContextPath()}+'/static/libs/bootstrap.min.js'"></script>
<script th:src="${#request.getContextPath()}+'/static/libs/jquery.slimscroll.min.js'"></script>
<script th:src="${#request.getContextPath()}+'/static/libs/fastclick.min.js'"></script>
<script th:src="${#request.getContextPath()}+'/static/libs/app.js'"></script>
<script type="text/javascript">
    var vm = new Vue({
        el:'#app',
        data:{
            loginname: '',
            pwd: '',
            captcha: '',
            error: false,
            errorMsg: '',
            src: 'captcha.jpg'
        },
        beforeCreate: function(){
            if(self != top){
                top.location.href = self.location.href;
            }
        },
        methods: {
            refreshCode: function(){
                this.src = "captcha.jpg?t=" + $.now();
            },
            login: function (event) {
                var data = "loginname="+vm.loginname+"&pwd="+vm.pwd+"&captcha="+vm.captcha;
                $.ajax({
                    type: "POST",
                    url: "/login/login",
                    data: data,
                    dataType: "json",
                    success: function(result){
                        if(result.code != 200){//登录成功
                            vm.error = true;
                            vm.errorMsg = result.msg;
                            vm.refreshCode();
                        }else{
                            location.href ="/sys/index";
                        }
                    }
                });
            }
        }
    });
</script>
</body>
</html>
